﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using GrewalCRM.Entities;
using GrewalCRM.BLL;

public partial class MasterCRM : System.Web.UI.MasterPage, ImasterCRM
{
    protected void Page_Load(object sender, EventArgs e)
    {
      if (!IsValidUser)
          Response.Redirect("default.aspx");
    }

    protected void Page_Prerender(object sender, EventArgs e)
    {
       
    }

    #region Public Property
    public bool IsValidUser
    {
      get{return uclMaster.IsValidUser;}
    }
    public UserCRM SessionUser
    {
      get
      {
        return uclMaster.SessionUser;
      }
    }
    public List<InstallersMaster> InstallersCache
    {
      get
      {
        if (Cache["INSTALLERS"] != null && Cache["INSTALLERS"] is List<InstallersMaster>)
          return Cache["INSTALLERS"] as List<InstallersMaster>;
        else
        {
          InstallersMaster_BLL installersBLL = new InstallersMaster_BLL();
          Cache["INSTALLERS"] = installersBLL.GetAllInstaller();
          return Cache["INSTALLERS"] as List<InstallersMaster>;
        }
      }
    }
    public List<ReffStatus> CallStatusCache
    {
      get
      {
        if (Cache["CALLSTATUS"] != null && Cache["CALLSTATUS"] is List<ReffStatus>)
          return Cache["CALLSTATUS"] as List<ReffStatus>;
        else
        {
          ReffStatus_BLL statusBLL = new ReffStatus_BLL();
          Cache["CALLSTATUS"] = statusBLL.GetAllStatus();
          return Cache["CALLSTATUS"] as List<ReffStatus>;
        }
      }
    }
    public List<DealersMaster> DealerCache
    {
      get
      {
        if (Cache["DEALER"] != null && Cache["DEALER"] is List<DealersMaster>)
          return Cache["DEALER"] as List<DealersMaster>;
        else
        {
          DealersMaster_BLL dealerBLL = new DealersMaster_BLL();
          Cache["DEALER"] = dealerBLL.GetAllDealer();
          return Cache["DEALER"] as List<DealersMaster>;
        }
      }
    }
    public List<ACBrands> ACBrandsCache
    {
      get
      {
        if (Cache["AC_BRAND"] != null && Cache["AC_BRAND"] is List<ACBrands>)
          return Cache["AC_BRAND"] as List<ACBrands>;
        else
        {
          ACBrands_BLL acBeandBLL = new ACBrands_BLL();
          Cache["AC_BRAND"] = acBeandBLL.GetAllACBrands();
          return Cache["AC_BRAND"] as List<ACBrands>;
        }
      }
    }   
    public string SiteDomainName
    {
      get { return ConfigurationManager.AppSettings["DOMAIN_NAME"].ToString(); }
    }
    public void ClearInstallersCache()
    {
      Cache.Remove("INSTALLERS");
    }
    public void ClearCallStatusCache()
    {
      Cache.Remove("CALLSTATUS");
    }
    public void ClearDealerCache()
    {
      Cache.Remove("DEALER");
    }
    public void ClearACBrandsCache()
    {
      Cache.Remove("AC_BRAND");
    }
    #endregion

}
